package summaries;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.text.DecimalFormat;

public class Results {

	private double T1;
	private double T2;
	private double T3;
	private double T4;
	private double T5;
	private double T6;
	private double T7;
	private double T8;
	private double T9;
	private double T10;
	private double T11;
	private double T;
	private String summary;
	
	public Results() {
		
	}
	
	public Results(double T1, double T2, double T3, double T4, double T5, double T6, double T7, double T8, double T9, double T10, double T11, double T, String summary) {
		this.T1  = T1;
		this.T2  = T2;
		this.T3  = T3;
		this.T4  = T4;
		this.T5  = T5;
		this.T6  = T6;
		this.T7  = T7;
		this.T8  = T8;
		this.T9  = T9;
		this.T10 = T10;
		this.T11 = T11;
		this.T   = T;
		this.summary = summary;
		
		// Temporary fix
		this.T1 = Math.abs(this.T1);
		this.T2 = Math.abs(this.T2);
		this.T3 = Math.abs(this.T3);
		this.T4 = Math.abs(this.T4);
		this.T5 = Math.abs(this.T5);
		this.T6 = Math.abs(this.T6);
		this.T7 = Math.abs(this.T7);
		this.T8 = Math.abs(this.T8);
		this.T9 = Math.abs(this.T9);
		this.T10 = Math.abs(this.T10);
		this.T11 = Math.abs(this.T11);
		this.T = Math.abs(this.T);
		
		this.T = this.T1 * 1/11 + this.T2 * 1/11 + this.T3 * 1/11 + this.T4 * 1/11 + this.T5 * 1/11 + this.T6 * 1/11 + this.T7 * 1/11 + this.T8 * 1/11 + this.T9 * 1/11 + this.T10 * 1/11 + this.T11 * 1/11;
		
		int tmp = 0;
		
		if (this.T1 > 1) {
			tmp = (int)this.T1;
			this.T1 -= tmp;
		}
		
		if (this.T2 > 1) {
			tmp = (int)this.T2;
			this.T2 -= tmp;
		}
		
		if (this.T3 > 1) {
			tmp = (int)this.T3;
			this.T3 -= tmp;
		}
		
		if (this.T4 > 1) {
			tmp = (int)this.T4;
			this.T4 -= tmp;
		}
		
		if (this.T5 > 1) {
			tmp = (int)this.T5;
			this.T5 -= tmp;
		}
		
		if (this.T6 > 1) {
			tmp = (int)this.T6;
			this.T6 -= tmp;
		}
		
		if (this.T7 > 1) {
			tmp = (int)this.T7;
			this.T7 -= tmp;
		}
		
		if (this.T8 > 1) {
			tmp = (int)this.T8;
			this.T8 -= tmp;
		}
		
		if (this.T9 > 1) {
			tmp = (int)this.T9;
			this.T9 -= tmp;
		}
		
		if (this.T10 > 1) {
			tmp = (int)this.T10;
			this.T10 -= tmp;
		}
		
		if (this.T11 > 1) {
			tmp = (int)this.T11;
			this.T11 -= tmp;
		}
		
		if (this.T > 1) {
			tmp = (int)this.T;
			this.T -= tmp;
		}
	}
	
	public void show() {
		System.out.println(summary);
		System.out.println("T1  = " + T1);
		System.out.println("T2  = " + T2);
		System.out.println("T3  = " + T3);
		System.out.println("T4  = " + T4);
		System.out.println("T5  = " + T5);
		System.out.println("T6  = " + T6);
		System.out.println("T7  = " + T7);
		System.out.println("T8  = " + T8);
		System.out.println("T9  = " + T9);
		System.out.println("T10 = " + T10);
		System.out.println("T11 = " + T11);
		System.out.println("T   = " + T);
	}
	
	public void appendToFile(String filename) {
		DecimalFormat twoDForm = new DecimalFormat("#.###");
		try {
			FileWriter fstream = new FileWriter(filename, true);
			BufferedWriter out = new BufferedWriter(fstream);
			String line = summary+","+twoDForm.format(T1)+","+twoDForm.format(T2)+","+twoDForm.format(T3)+","+twoDForm.format(T4)+","+twoDForm.format(T5)+","+twoDForm.format(T6)+","+twoDForm.format(T7)+","+twoDForm.format(T8)+","+twoDForm.format(T9)+","+twoDForm.format(T10)+","+twoDForm.format(T11)+","+twoDForm.format(T)+"\n";
			out.write(line);
			out.close();
		} catch (Exception e) {
			
		}
	}
	
	public String toString() {
		
		DecimalFormat twoDForm = new DecimalFormat("#.###");
		
		String s = "";
		s = twoDForm.format(T1) + "\t" + twoDForm.format(T2) + "\t" + twoDForm.format(T3) + "\t" + twoDForm.format(T4) + "\t" + 
			twoDForm.format(T5) + "\t" + twoDForm.format(T6) + "\t" + twoDForm.format(T7) + "\t" + twoDForm.format(T8) + "\t" +
			twoDForm.format(T9) + "\t" + twoDForm.format(T10) + "\t" + twoDForm.format(T11) + "\t" + twoDForm.format(T);
		return s;
	}
}
